let itemWidth = 0; //图片宽度
let maxHeight = 0; //每张图片的最大高度
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    type:'',
    productList:[],
    itemWidth: 0 //图片宽度
  },
  attached(){
    wx.getSystemInfo({
      success: (res) => {
        var percentage = 750 / res.windowWidth;
        var margin = 60 / percentage;
        itemWidth = (res.windowWidth - margin) / 2;
        maxHeight = itemWidth / 0.5
      }
    });
  },

  /**
   * 组件的方法列表
   */
  methods: {
    fillData: function(isPull, listData,type) {         
      if(isPull){
        this.setData({
          productList:[]
        })
      }
      // console.log(listData)
      this.setData({
        type:type
      })
      let tempList=[]
      for (var i = 0, len = listData.length; i < len; i++) {
        var tmp = listData[i];
        //计算每张图片的高度和宽度
        tmp.width = parseInt(tmp.width);
        tmp.height = parseInt(tmp.height);
        tmp.itemWidth = itemWidth
        var per = tmp.width / tmp.itemWidth;
        tmp.itemHeight = tmp.height / per;
        if (tmp.itemHeight > maxHeight) {
          tmp.itemHeight = maxHeight;
        }
        //计算并将每条数据放入瀑布流的左列或右列显示
        tempList.push(tmp);
        
      }

      let productList=this.data.productList.concat(tempList)
      this.setData({
        productList: productList
      });
    }
  }
})
